package sun.flower.leetcode;

/**
 * 判断数列是否是单调数列
 * @Author :tuhan
 * @Date : 2021/2/28 15:34
 **/
public class IsMonotonic {

    public static void main(String[] args){
        int[] arr = {3,3,2,1};

        boolean isMonotonic = isMonotonic(arr);

        System.out.println(isMonotonic);

    }

    public static boolean isMonotonic(int[] arr) {
        int r = 0; //
        int j = 0;//单调递增
        boolean f = true;//是单调函数
        for(int i = 0;i<arr.length-1;i++){
            if(arr[i]<arr[i+1]){
                r =1;
            }else if(arr[i]>arr[i+1]){
                j =1;
            }
            if((r+j)==2){
                f = false;
                break;
            }
        }
        return f;
    }
}
